package edu.mit.csail.relo.ui;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;

import edu.mit.csail.relo.agent.BrowseModel;
import edu.mit.csail.relo.parts.ReloController;

// provides support for working with both ReloViews and Editors
public abstract class ReloAction implements IEditorActionDelegate, IViewActionDelegate {

	protected BrowseModel bm = null;
	protected ReloController rc = null;
	protected IToolBarManager tbm = null;

	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
		if (targetEditor == null) return;
	    ReloEditor reloEditor = (ReloEditor) targetEditor;
		bm = reloEditor.bm;
        rc = reloEditor.getReloController();
        tbm  = reloEditor.getEditorSite().getActionBars().getToolBarManager();
        initAction();
	}
	public void init(IViewPart view) {
		ReloView reloView = (ReloView) view;
		bm = reloView.bm;
        rc = reloView.getReloController();
        tbm  = reloView.getViewSite().getActionBars().getToolBarManager();
        initAction();
	}
	
	public void initAction() {
	}

	public abstract void run(IAction action);

	public void selectionChanged(IAction action, ISelection selection) {}


}
